from multiprocessing import Process
import mmap
import contextlib
import time


def writer():
    i = 0
    while True:
        time.sleep(0.5)
        with contextlib.closing(mmap.mmap(-1, 1024, tagname='cnblogs', access=mmap.ACCESS_WRITE)) as mem:
            mem.seek(0)
            m_data = '%s  Write data to share memory!' % (i)
            print(m_data)
            mem.write(str.encode(m_data))
            mem.flush()


if __name__ == '__main__':
    p_writer = Process(target=writer, args=())
    p_writer.start()
    p_writer.join()
